<template>
  <div>
    <el-row>
        <el-col :span="12">
            <el-card shadow="hover" class="card">
                <el-row>
                    <el-col :span="12"><h3>个人资料</h3></el-col>
                </el-row>
                <el-row>
                    <el-col :span="13">
                        <el-row>欢迎进入高校毕业管理平台</el-row>
                        <el-row style="">右侧头像点击更换</el-row>
                        <el-row>
                            <el-row>
                                <el-col :span="24">命运从不会欺负你一个人</el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="24">相信自己会成为下个时代的主角</el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="24">放手去做吧！</el-col>
                            </el-row>
                        </el-row>
                    </el-col>
                    <el-col :span="11">
                        <!-- <img src="../../assets/index.jpg" alt="" style="width: 100%"> -->
                        <el-upload
                            style="border: 1px solid;"
                            class="avatar-uploader"
                            action="http://localhost:8000/public/upload"
                            :show-file-list="false"
                            :on-success="handleAvatarSuccess"
                            :before-upload="beforeAvatarUpload">
                            <img v-if="imageUrl" :src="imageUrl" class="avatar" style="width: 100%">
                            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                        </el-upload>
                    </el-col>
                </el-row>
                <el-row>&nbsp;</el-row>
                <el-row>
                    <el-col :span="3" class="keys">昵称</el-col>
                    <el-col :span="5">{{userdetail.nickname}}</el-col>
                    <el-col :span="5" class="keys">年级</el-col>
                    <el-col :span="3">{{userdetail.graduateyear}}</el-col>
                    <el-col :span="2" class="keys">学号</el-col>
                    <el-col :span="3">{{userdetail.studentnumber}}</el-col>
                </el-row>
                <el-row>
                    <el-col :span="3" class="keys">学院</el-col>
                    <el-col :span="5">{{userdetail.college}}</el-col>
                    <el-col :span="5" class="keys">出生日期</el-col>
                    <el-col :span="6">{{userdetail.birthdate}}</el-col>
                </el-row>
                <el-row>
                    <el-col :span="3" class="keys">专业</el-col>
                    <el-col :span="5">{{userdetail.profession}}</el-col>
                    <el-col :span="5" class="keys">班级</el-col>
                    <el-col :span="5">{{userdetail.classname}}</el-col>
                </el-row>
                <el-row>
                    <el-col :span="3" class="keys">民族</el-col>
                    <el-col :span="5">{{userdetail.nation}}</el-col>
                    <el-col :span="3" class="keys">学历</el-col>
                    <el-col :span="3">{{userdetail.education}}</el-col>
                    <el-col :span="4" class="keys">生源地</el-col>
                    <el-col :span="5">{{userdetail.familyaddress}}</el-col>
                </el-row>
                <el-row>
                    <el-col :span="3" class="keys">电话</el-col>
                    <el-col :span="6">{{userdetail.phonenumber}}</el-col>
                    <el-col :span="3" class="keys">邮箱</el-col>
                    <el-col :span="3">{{userdetail.mail}}</el-col>
                </el-row>
            </el-card>
        </el-col>
        <el-col :span="11" style="margin-top: 2.8%" v-show="loading">
            <p>今日公告</p>
            <template>
                <el-carousel indicator-position="outside">
                    <el-carousel-item v-for="item in 4" :key="item">
                    <h3>{{ item }}个小兔子</h3>
                    </el-carousel-item>
                </el-carousel>
            </template>
        </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
    name: 'Home',
    data() {
        return {
            aa: '55',
            imageUrl: '',
            userdetail: {},
            loading: false
        }
    },
    created() {
        this.util.post('/user/loadUserdetailByUid', {uid: localStorage.getItem('uid')}).then(res => {
            this.userdetail = res.data
            this.imageUrl = res.data.userimg
            
        })
        let that = this;
        setTimeout(() => {
            that.loading = true
        }, 2000);
    },
    methods: {
        handleAvatarSuccess(res, file) {
            this.imageUrl = file.response;
            this.userdetail.userimg = file.response;
            this.util.post('/user/updateByPrimaryKey',  this.userdetail);
        },
        beforeAvatarUpload(file) {
            const isJPG = file.type === 'image/jpeg';
            const isLt2M = file.size / 1024 / 1024 < 2;

            if (!isJPG) {
                this.$message.error('上传头像图片只能是 JPG 格式!');
            }
            if (!isLt2M) {
                this.$message.error('上传头像图片大小不能超过 2MB!');
            }
            
            return isJPG && isLt2M;
        }
    }
}
</script>

<style scoped>
.card {
    margin: 10px;
    line-height: 28px;
    position:relative;
	animation:mymove 2s infinite;
	-webkit-animation:mymove 2s infinite; /*Safari and Chrome*/
    animation-iteration-count: 1;
}

.keys {
    font-size: 14px;
    color: darkgray;
}

@keyframes mymove
{
	from {left:70px;}
	to {left:0px;}
}

@-webkit-keyframes mymove /*Safari and Chrome*/
{
	from {left:70px;}
	to {left:0px;}
}

.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }

  .el-carousel__item h3 {
    color: #475669;
    font-size: 18px;
    opacity: 0.75;
    line-height: 300px;
    margin: 0;
  }
  
  .el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
  }
  
  .el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
  }
</style>